﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Salary_Advance_Form.aspx.cs"
    Inherits="Trig_AMJ_HR_Forms.Layouts.Trig_AMJ_HR_Forms.Salary_Advance_Form" DynamicMasterPageFile="~masterurl/default.master" %>

<%@ Register TagPrefix="trig" TagName="userInfo" Src="~/_controltemplates/Trig_AMJ_IT_Forms/UserProfileInfo.ascx" %>
<%@ Register TagPrefix="trig" TagName="AdvanceComments" Src="~/_controltemplates/Trig_AMJ_AMG_Forms/TrigAMJFormsComments/TrigAMJFormsCommentsUserControl.ascx" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <link rel="Stylesheet" type="text/css" href="/_layouts/1033/STYLES/Themable/FORMS.CSS" />
    <link rel="Stylesheet" type="text/css" href="/Style Library/Al Majed/CSS/Trig_HR.css" />
    <script language="javascript" src="/_layouts/Scripts/validation.js" type="text/javascript"></script>
    <style type="text/css">
        #s4-leftpanel
        {
            display: none;
        }
        .s4-ca
        {
            margin-left: 0px;
        }
        .ms-validations
        {
            color: Red;
        }
        .style2
        {
            width: 373px;
        }
        .style3
        {
            width: 366px;
        }
        body, td, th
        {
            font-size: 8pt;
            font-family: Verdana, Arial, sans-serif;
        }
    </style>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <asp:Panel ID="pnlFullForm" runat="server" CssClass="pnlAMFform">
        <table cellpadding="0" cellspacing="0" width="800" class="tbl-main">
            <tr>
                <td colspan="4" class="formtitle">
                    Salary Advance Form
                </td>
            </tr>
            <tr>
                <td width="184" colspan="1">
                    Reference Number :
                </td>
                <td colspan="2">
                    <asp:Label ID="lblSalAdvReqNo" runat="server" Text="Reference number will be generated upon save"
                        Font-Bold="True" Font-Size="XX-Small" ForeColor="Red" CssClass="ms-long ms-spellcheck-true"></asp:Label>
                </td>
                <td width="217" colspan="1" rowspan="3" align="right" class="UserInfo-Sec-td">
                    <trig:userInfo runat="server" ID="userInfo" Visible="true" />
                </td>
            </tr>
            <tr>
                <td colspan="1">
                    Request Date :
                </td>
                <td colspan="2">
                    <SharePoint:DateTimeControl ID="dtpDate" runat="server" DateOnly="true" Enabled="false"
                        LocaleId="2057" />
                </td>
            </tr>
            <asp:Panel runat="server" ID="pnlSec">
                <tr>
                    <td colspan="2">
                        <asp:RadioButtonList ID="rdBtn" AutoPostBack="true" runat="server" RepeatDirection="Horizontal"
                            OnSelectedIndexChanged="rdBtn_SelectedIndexChanged" RepeatLayout="Flow">
                            <asp:ListItem Text="Logged in User" Value="0" Selected="True"></asp:ListItem>
                            <asp:ListItem Text="On Behalf of" Value="1"></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
            </asp:Panel>
            <asp:Panel ID="pnlReqEmpInf" runat="server" Visible="false">
                <tr>
                    <td class="tdHeadingTextLeftAlign" colspan="4">
                        Requested Employee Information
                    </td>
                </tr>
                <tr>
                    <td>
                        Name :<span title="This is a required field." class="ms-validations"><strong>*</strong></span>
                    </td>
                    <td width="226">
                        <SharePoint:PeopleEditor ID="pplReqUser" runat="server" MultiSelect="false" AutoPostBack="true"
                            Width="250px" />
                        <asp:TextBox ID="txtReqUser" runat="server" ReadOnly="true" Width="250px" Visible="false"
                            Enabled="false"></asp:TextBox>
                    </td>
                    <td width="171">
                        Employee ID : <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                    </td>
                    <td>
                        <asp:TextBox ID="txtReqEmpId" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Division :
                    </td>
                    <td>
                        <asp:TextBox ID="txtReqDivision" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                    </td>
                    <td>
                        Department :
                    </td>
                    <td>
                        <asp:TextBox ID="txtReqDept" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Designation :
                    </td>
                    <td>
                        <asp:TextBox ID="txtReqDesignation" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                    </td>
                    <td>
                        Mobile Number :
                    </td>
                    <td>
                        <asp:TextBox ID="txtReqMobileNo" runat="server" Width="250px" onkeypress="return isNumberKey(this)"></asp:TextBox>
                    </td>
                </tr>
            </asp:Panel>
            <tr>
                <td>
                    Date of Employment <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <SharePoint:DateTimeControl ID="dtDOE" runat="server" DateOnly="true" Enabled="false"
                        LocaleId="2057" />
                </td>
                <td>
                    Basic Salary <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtBasicSalary" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="4" class="tdHeadingTextLeftAlign">
                    Advance Details
                </td>
            </tr>
            <tr>
                <td>
                    Advance Amount <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtAdvance" onkeypress="return isNumberKey(this)"
                        OnTextChanged="txtAdvance_TextChanged"></asp:TextBox>
                </td>
                <td>
                    Instalment <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtInstalment" Text="" AutoPostBack="true"></asp:TextBox>
                </td>
            </tr>
            <asp:UpdatePanel runat="server" ID="uptAdv">
                <ContentTemplate>
                    <tr>
                        <td>
                            Amount to be deducted p/m
                        </td>
                        <td>
                            <asp:TextBox runat="server" ID="txtDeduction" ReadOnly="true"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Starts on :
                        </td>
                        <td>
                            <SharePoint:DateTimeControl ID="dtStDate" runat="server" DateOnly="true" Enabled="false"
                                LocaleId="2057" />
                        </td>
                        <td>
                            Ends on :
                        </td>
                        <td>
                            <SharePoint:DateTimeControl ID="dtEndDate" runat="server" DateOnly="true" Enabled="false"
                                LocaleId="2057" />
                        </td>
                    </tr>
                </ContentTemplate>
            </asp:UpdatePanel>
            <tr>
                <td colspan="4" class="tdHeadingTextLeftAlign">
                    Outstanding Balance
                </td>
            </tr>
            <tr>
                <td>
                    Outstanding Amount
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtOS" ReadOnly="true" Text="5000"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Total Outstanding Amount <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtTotOS" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="4" class="tdHeadingTextLeftAlign">
                    Comments / Workflow Area
                </td>
            </tr>
            <tr>
                <td colspan="4" style="padding: 10px;">
                    <trig:AdvanceComments ID="AdvComments" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <table width="100%" cellpadding="0" cellspacing="0" class="Section-Approver">
                        <asp:Panel ID="pnlCommentArea" runat="server" class="Section-Approver">
                            <tr>
                                <td colspan="4" class="AppHeading">
                                    <strong>Comments</strong><span class="ms-validations" title="This is a required field."><strong>
                                        *</strong></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="tdCell">
                                    <asp:Image ID="ImgUser" runat="server" Height="50px" Width="50px" />
                                    <br />
                                    <asp:Label ID="LblCommentsUserName" runat="server" Font-Bold="True" Font-Size="XX-Small"
                                        ForeColor="#003399" Text=""></asp:Label>
                                </td>
                                <td colspan="3" class="tdCell">
                                    <asp:TextBox ID="TxtComments" runat="server" TextMode="MultiLine" Width="600px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr id="upAtt" runat="server">
                                <td class="tdCell">
                                    Upload Attachment
                                </td>
                                <td colspan="3" class="tdCell">
                                    <asp:FileUpload ID="upfile" runat="server" CssClass="ms-fileinput" Width="250px" />
                                </td>
                            </tr>
                        </asp:Panel>
                        <asp:Panel ID="pnlForward" runat="server" Visible="false">
                            <tr>
                                <td colspan="4" style="text-align: left; background-color: #121e66; color: #ffffff;
                                    font-weight: bold; padding: 10px;">
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbSendBack" runat="server" Text="Send Back" GroupName="Users"
                                                            AutoPostBack="true" onclick="javascript:fnSendBackUsers(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbSendBack" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbForwardOthers" runat="server" Text="Forward to other user"
                                                            AutoPostBack="true" GroupName="Users" onclick="javascript:fnForwardUsers(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbForwardOthers" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbForward" runat="server" Text="Forward" GroupName="Users"
                                                            AutoPostBack="true" onclick="javascript:fnForword(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbForward" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
                                                <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                                                    <ContentTemplate>
                                                        <asp:Label ID="lblWFStaticUser" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow"></asp:Label>
                                                        <asp:Label ID="lblSendBacktoUser" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow" Visible="false"></asp:Label>
                                                        <asp:Label ID="lblsendBackUserValue" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow"></asp:Label>
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr style="padding: 10px; display: none" id="trotherUsers">
                                <td style="padding: 10px; font-weight: bold; color: #121e66;" width="130px">
                                    User Name :
                                </td>
                                <td style="padding: 10px;" colspan="3">
                                    <asp:Label ID="lblCNTSectionMsg" runat="server" Text=""></asp:Label>
                                    <SharePoint:PeopleEditor ID="pplcnt" runat="server" MultiSelect="false" AllowEmpty="false"
                                        Width="250px" ForeColor="Red" AutoPostBack="false" />
                                </td>
                            </tr>
                        </asp:Panel>
                        <asp:Panel runat="server" ID="btnCntrls">
                            <tr>
                                <td colspan="4">
                                    <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                                        <ContentTemplate>
                                            <asp:Label ID="lblError" runat="server" CssClass="error-msg" Text=""></asp:Label>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" class="tblButtons" style="padding-top: 5px;">
                                    <asp:HiddenField runat="server" ID="ckSubmit" Value="false" />
                                    <asp:Button ID="btnSubmit" runat="server" CssClass="btn-Submit" Text="Submit" OnClientClick="javascript:return fnValidation();"
                                        OnClick="btnSubmit_Click" />
                                    <asp:Button ID="btnApprove" runat="server" CssClass="btn-Approver" Text="Approve"
                                        OnClick="btnApprove_Click" OnClientClick="javascript:return fnValidation();"
                                        Visible="false" />
                                    <asp:Button ID="btnReject" runat="server" CssClass="btn-Reject" Text="Reject" Visible="false"
                                        OnClick="btnReject_Click" OnClientClick="javascript:return fnValidation();" />
                                    <input id="btnCancel" class="btn-Cancel" type="button" value="Close" accesskey="C"
                                         onclick="window.parent.history.back()"
                                        runat="server" />
                                </td>
                            </tr>
                        </asp:Panel>
                    </table>
                </td>
            </tr>
            <asp:Panel ID="pnlView" runat="server" Visible="false">
                <tr>
                    <td colspan="4" style="text-align: center;">
                        <input id="btnViewClose" class="btn-Cancel" type="button" onclick="window.parent.history.back()"
                            value="Close" accesskey="C" />
                    </td>
                </tr>
            </asp:Panel>
        </table>
    </asp:Panel>
    <asp:Panel ID="pnlAccessDenied" runat="server" Visible="false" CssClass="pnlAMFform">
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td style="text-align: center;">
                    <asp:Label ID="lblAccessDeniedMsg" runat="server" Text="" Font-Size="Medium" ForeColor="Red"
                        Font-Bold="True" Visible="false"></asp:Label>
                    <asp:Label ID="lblUserNotvailable" runat="server" Text="" Font-Size="Medium" ForeColor="Red"
                        Font-Bold="True" Visible="false"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px;">
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/_layouts/1033/IMAGES/IRForm/AccessDeniedImage.png" />
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px">
                    <input id="butonclose" class="ms-ButtonHeightWidth" type="button" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancel clicked'); return false;"
                        value="Close" accesskey="C" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <script language="javascript" type="text/javascript">
        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }

        function ClearValue() {

            document.getElementById('<%= txtDeduction.ClientID %>').value = "";
            document.getElementById('<%= dtStDate.Controls[0].ClientID  %>').value = "";
            document.getElementById('<%= dtEndDate.Controls[0].ClientID  %>').value = "";
            document.getElementById('<%= txtTotOS.ClientID  %>').value = "";
        }

        function ClearValues() {
            document.getElementById('<%= txtInstalment.ClientID %>').value = "";
            ClearValue();
        }

        //        function ClearValues() {
        //            // set number of days to add
        //            var interval = document.getElementById('<%= txtInstalment.ClientID  %>').value;

        //            var today = new Date();
        //            var startDate = new Date(Date.parse(today));

        //            var expDate = startDate;
        //            expDate.setDate(startDate.getDate() + interval);


        //            var dd = expDate.getDate();
        //            var mm = expDate.getMonth() + 1; //January is 0!
        //            var yyyy = expDate.getFullYear();

        //            if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } var result = dd + '/' + mm + '/' + yyyy;

        //            document.getElementById('<%= dtStDate.Controls[0].ClientID  %>').value = result;

        //        };


    </script>
    <script language="javascript" type="text/javascript">
        document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
        document.getElementById('<%= lblError.ClientID  %>').style.display = "none";


        function Trim(TrimString) {
            var tempObj;
            if (TrimString) { tempObj = TrimString; TrimString = tempObj.value; }
            if (TrimString == "undefined" || TrimString == null) return null;
            if (TrimString.length == 0) TrimString = "";
            else {
                var Lcont = 0, TempStrArray = TrimString.split(" "), Rcont = TempStrArray.length - 1;
                while (TempStrArray[Lcont] == "") Lcont++; while (TempStrArray[Rcont] == "") Rcont--;
                if (Rcont < Lcont) TrimString = ""; else
                    for (TrimString = TempStrArray[Lcont], Lcont++; Lcont <= Rcont; Lcont++) TrimString += " " + TempStrArray[Lcont];
                var re = /\'|/g;
                TrimString = TrimString.replace(re, "");
            }
            if (tempObj && TrimString != "undefined" && TrimString != null)
            { tempObj.value = TrimString; return tempObj }
            else return TrimString;
        }

        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.search);
            if (results == null)
                return "";
            else
                return decodeURIComponent(results[1].replace(/\+/g, " "));
        }


        function fnValidation() {
            debugger;
            var rval = true;
            debugger;
            var querystringval = getParameterByName('Mode');
            var ErrorMsg = "";
            var objFocus;
            var reqType;

            Trim(document.getElementById('<%= TxtComments.ClientID  %>'));
            var cmnts = document.getElementById('<%= TxtComments.ClientID  %>')

            Trim(document.getElementById('<%= pplReqUser.ClientID  %>'));
            Trim(document.getElementById('<%= txtReqEmpId.ClientID  %>'));
            Trim(document.getElementById('<%= dtDOE.ClientID  %>'));
            Trim(document.getElementById('<%= txtBasicSalary.ClientID  %>'));
            Trim(document.getElementById('<%= txtTotOS.ClientID  %>'));
            Trim(document.getElementById('<%= txtInstalment.ClientID  %>'));

            var user = document.getElementById('<%= pplReqUser.ClientID  %>');
            var id = document.getElementById('<%= txtReqEmpId.ClientID  %>');
            var doe = document.getElementById('<%= dtDOE.Controls[0].ClientID  %>');
            var basic = document.getElementById('<%= txtBasicSalary.ClientID  %>');
            var adv = document.getElementById('<%= txtAdvance.ClientID  %>');
            var os = document.getElementById('<%= txtTotOS.ClientID  %>')
            var instalment = document.getElementById('<%= txtInstalment.ClientID  %>')


            var MyRadio = document.getElementById("<%=rdBtn.ClientID%>");
            var options = MyRadio.getElementsByTagName("input");
            var radVal;
            for (x = 0; x < options.length; ++x) {
                if (options[x].checked) {
                    radVal = x;
                }
            }

            if (querystringval == "New") {
                if (isEmpty(user) && radVal == 1) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = user;
                    rval = false;
                }
                else if (isEmpty(id) && radVal == 1) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = id;
                    rval = false;
                }

                else if (isEmpty(doe)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = doe;
                    rval = false;
                }

                else if (isEmpty(basic)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = basic;
                    rval = false;
                }
                else if (isEmpty(adv)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = adv;
                    rval = false;
                }
                else if (isEmpty(instalment)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = instalment;
                    rval = false;
                }

                else if (isEmpty(os)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = os;
                    rval = false;
                }
                else {
                    if (isEmpty(cmnts)) {
                        ErrorMsg = "Fields marked with (*) cannot be left blank";
                        objFocus = cmnts;
                        rval = false;
                    }
                }
            }
            else {
                if (isEmpty(cmnts)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = cmnts;
                    rval = false;
                }
            }

            if (rval == false) {
                document.getElementById('<%= lblError.ClientID  %>').style.display = "block";
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = ErrorMsg;
                objFocus.focus();
            }
            else {
                document.getElementById('<%= ckSubmit.ClientID  %>').value = "True";
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
                document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
            }
            return rval;
        }
    </script>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    Salary Advance Form
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    Salary Advance Form
</asp:Content>
